home *** CD-ROM | disk | FTP | other *** search
/ Megahits 5 / Megahits 5 (1994)(GTI - Rhein-Main-Soft)(DE)(Disc 2 of 2)[!].iso / archive / show / supervw_lib_82.lha / superview-lib / Programmers / Example_Tools / MicroView / MicroView.c < prev    next >
C/C++ Source or Header  |  1994-09-10  |  7KB  |  258 lines

  1. /* ======================================================================== */
  2. /* = Programmname    : MicroView V7.1                      = */
  3. /* =                                      = */
  4. /* ======================================================================== */
  5. /* = Author/Copyright : (c) 1994 by Andreas Ralph Kleinert.               = */
  6. /* =               Freeware. All rights reserved.              = */
  7. /* =                                      = */
  8. /* =                   Use it as an example for programming               = */
  9. /* =                   superview.library !                                = */
  10. /* =                                      = */
  11. /* ======================================================================== */
  12. /* = Function          : Shows Graphics via superview.library.             = */
  13. /* =                                      = */
  14. /* ======================================================================== */
  15. /* = Last Update      : 15.7.1994                      = */
  16. /* =                                      = */
  17. /* ======================================================================== */
  18. /* = Remarks          : Needs "asl.library" V37+                          = */
  19. /* =                and "superview.library" V2+.                      = */
  20. /* =                                      = */
  21. /* =                    RUNS ONLY FROM CLI/SHELL !                        = */
  22. /* =                                      = */
  23. /* ======================================================================== */
  24. /* = Compiler          : SAS/C V6.51                        = */
  25. /* =                (smakefile)                                       = */
  26. /* ======================================================================== */
  27.  
  28. /* to prevent this program from using standard startup-code ("LIB:c.o"),
  29.    #define NO_STARTUP at this point and change smakefile not to link
  30.    with startup-code.
  31.  
  32.    WARNING :
  33.    Currently the version without startup-code does seem to crash,
  34.    when it is the first program to open superview.library.
  35.    If it has been opened by other programs before, there are no
  36.    problems.
  37. */
  38.  
  39. #define __USE_SYSBASE
  40.  
  41. #include <intuition/intuition.h>
  42.  
  43. #include <superview/superview.h>
  44. #include <dos/dosextens.h>
  45. #include <dos/rdargs.h>
  46. #include <libraries/asl.h>
  47.  
  48. #include <proto/exec.h>
  49. #include <proto/dos.h>
  50. #include <proto/asl.h>
  51. #include <proto/superview.h>
  52.  
  53.  
  54. /* *************************************************** */
  55. /* *                             * */
  56. /* * Error-Messages for Leave() :                    * */
  57. /* *                             * */
  58. /* *************************************************** */
  59.  
  60. #define copyright_text "MicroView V7.1 (Freeware)\n(c) 1994 by Andreas R. Kleinert.\n"
  61. #define options        "FILE/A"
  62. #define OS37needed     "You need OS V2.04+ !"
  63. #define asllib_text    "You need \42asl.library\42 V37+ !"
  64. #define svlib_text     "You need \42superview.library\42 V2+ !"
  65.  
  66. char ver_text [] = "\0$VER: MicroView V7.1 (15.7.94)";
  67.  
  68.  
  69. /* *************************************************** */
  70. /* *                             * */
  71. /* * MACROs for Version-Tests                 * */
  72. /* *                             * */
  73. /* *************************************************** */
  74.  
  75. #define LibVer(x) ( ((struct Library *) x)->lib_Version )
  76. #define OS_VER      LibVer(SysBase)
  77.  
  78.  
  79. /* *************************************************** */
  80. /* *                             * */
  81. /* * Function Declarations                 * */
  82. /* *                             * */
  83. /* *************************************************** */
  84.  
  85. ULONG           main(void);
  86. ULONG MicroView_Show(char *filename);
  87. ULONG Leave(char *endtext, ULONG code);
  88.  
  89.  
  90. /* *************************************************** */
  91. /* *                             * */
  92. /* * Additional Base Declarations             * */
  93. /* *                             * */
  94. /* *************************************************** */
  95.  
  96. #ifdef NO_STARTUP
  97. struct ExecBase      *SysBase       = N;
  98. struct DosLibrary    *DOSBase       = N;
  99. #else
  100. extern struct ExecBase   *SysBase;
  101. extern struct DosLibrary *DOSBase;
  102. #endif /* NO_STARTUP */
  103.  
  104. struct Library       *AslBase       = N;
  105. struct SuperViewBase *SuperViewBase = N;
  106.  
  107.  
  108. /* *************************************************** */
  109. /* *                             * */
  110. /* * MAIN                         * */
  111. /* *                             * */
  112. /* *************************************************** */
  113.  
  114. ULONG          __aligned rdopts[8];
  115. struct TagItem __aligned tags[4];
  116.  
  117. ULONG main(void)
  118. {
  119.  struct RDArgs  *rdargs;
  120.  ULONG           retcode = 0;
  121.  
  122. #ifdef NO_STARTUP
  123.  
  124.  SysBase = (*((struct ExecBase **)4));
  125.  DOSBase = (APTR) OpenLibrary("dos.library", 0);
  126.  
  127. #endif /* NO_STARTUP */
  128.  
  129.  if(   (OS_VER          < 37) 
  130.     || (LibVer(DOSBase) < 37) ) return(Leave(OS37needed, 100));
  131.  
  132.  PutStr(copyright_text);
  133.  
  134.  AslBase = (struct Library *) OpenLibrary("asl.library", 37);
  135.  if(!AslBase) return(Leave(asllib_text, 102));
  136.  
  137.  SuperViewBase = (struct SuperViewBase *) OpenLibrary("superview.library", 2);
  138.  if(!SuperViewBase) return(Leave(svlib_text, 103));
  139.  
  140.  rdargs = ReadArgs(options, (LONG *) &rdopts[0], NULL);
  141.  if(!rdargs)
  142.   {
  143.    struct FileRequester *request;
  144.    char                  namebuffer [256];
  145.  
  146.    namebuffer[0] = (char) 0;
  147.  
  148.    tags[0].ti_Tag  = (Tag)   ASL_Hail;
  149.    tags[0].ti_Data = (ULONG) "Select Picture File :";
  150.  
  151.    tags[1].ti_Tag  = (Tag)   ASL_OKText;
  152.    tags[1].ti_Data = (ULONG) "Display";
  153.  
  154.    tags[2].ti_Tag  = (Tag)   ASL_CancelText;
  155.    tags[2].ti_Data = (ULONG) "Quit";
  156.  
  157.    tags[3].ti_Tag  = (Tag)   TAG_DONE;
  158.    tags[3].ti_Data = (ULONG) N;
  159.  
  160.    request = AllocAslRequest(ASL_FileRequest, N);
  161.    if(request)
  162.     {
  163.      if(AslRequest(request, &tags[0]))
  164.       {
  165.        strcpy(namebuffer, request->rf_Dir);
  166.        if(    (namebuffer[strlen(namebuffer)-1] !=      ':')
  167.            && (namebuffer[strlen(namebuffer)-1] !=      '/')
  168.            && (namebuffer[0]                    != (char) 0) ) strcat(namebuffer, "/");
  169.  
  170.        strcat(namebuffer, request->rf_File);
  171.  
  172.        if(namebuffer[0] != (char) 0) retcode = MicroView_Show(namebuffer);
  173.       }
  174.  
  175.      FreeAslRequest(request);
  176.     }
  177.   }else
  178.   {
  179.    retcode = MicroView_Show((UBYTE *) rdopts[0]);
  180.  
  181.    FreeArgs(rdargs);
  182.   }
  183.  
  184.  return(Leave(N, retcode));
  185. }
  186.  
  187. /* *************************************************** */
  188. /* *                             * */
  189. /* * Show-Function                     * */
  190. /* *                             * */
  191. /* *************************************************** */
  192.  
  193. ULONG MicroView_Show(char *filename)
  194. {
  195.  APTR handle;
  196.  struct Window *win;
  197.  ULONG retval = SVERR_NO_ERROR;
  198.  
  199.  handle = SVL_AllocHandle(N);
  200.  if(handle)
  201.   {
  202.    if(!(retval = SVL_InitHandleAsDOS(handle, N)))
  203.     {
  204.      if(!(retval = SVL_SetWindowIDCMP(handle, IDCMP_MOUSEBUTTONS, N)))
  205.       {
  206.        if(!(retval = SVL_SetScreenType(handle, CUSTOMSCREEN, N)))
  207.         {
  208.          if(!(retval = SVL_SuperView(handle, filename)))
  209.           {
  210.            if(!(retval = SVL_GetWindowAddress(handle, &win, N)))
  211.             {
  212.              if(win)
  213.               {
  214.                WaitPort(win->UserPort);
  215.               }
  216.             }
  217.           }
  218.         }
  219.       }
  220.     }
  221.    
  222.    SVL_FreeHandle(handle);
  223.  
  224.   }else retval = SVERR_NO_HANDLE;
  225.  
  226.  if(retval) return(Leave(SVL_GetErrorString(retval), 0));
  227.  
  228.  return(0);
  229. }
  230.  
  231. /* *************************************************** */
  232. /* *                             * */
  233. /* * LEAVE : Global Exit Function Replacement         * */
  234. /* *                             * */
  235. /* *************************************************** */
  236.  
  237. ULONG Leave(char *endtext, ULONG code)
  238. {
  239.  if(SuperViewBase) CloseLibrary((APTR) SuperViewBase);
  240.  if(AslBase)       CloseLibrary((APTR) AslBase);
  241.  if(DOSBase)
  242.   {
  243.    if(endtext)
  244.     {
  245.      Write(Output(), endtext, strlen(endtext));
  246.      Write(Output(), "\n", 1);
  247.     }
  248.   }
  249.  
  250. #ifdef NO_STARTUP
  251.  
  252.  if(DOSBase) CloseLibrary((APTR) DOSBase);
  253.  
  254. #endif /* NO_STARTUP */
  255.  
  256.  return(code);
  257. }
  258.